package com.yuncheng.spcyApi.controller;

import java.io.File;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.bo.ImportUserPxjlBo;
import com.yuncheng.spcyApi.bo.UserPxjlBo;
import com.yuncheng.spcyApi.busService.FlowJobBlsxService;
import com.yuncheng.spcyApi.spcyService.ZdyUploadFileService;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import com.yuncheng.spcyApi.service.IYcSysUserService;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.spcyApi.service.ISysUserPxjlService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import utils.DateConversionUtils;
import utils.ExcelUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;

/**
 * @Description: 系统-用户培训记录
 * @Author: csx
 * @Date: 2023-03-03
 * @Version: V1.0
 */
@Api(tags = "系统-用户培训记录接口")
@RestController
@RequestMapping("/api/spzx-spcy/sysUserPxjl")
public class SysUserPxjlController extends BaseController<SysUserPxjl, ISysUserPxjlService> {

    private static final Logger log = LoggerFactory.getLogger(SysUserPxjlController.class);

    @Resource
    private ISysUserPxjlService sysUserPxjlService;

    @Resource
    private ISpcyLogService spcyLogService;

    @Resource
    private LocalFileUploadUtils localFileUploadUtils;

    @Resource
    private MyExcelUtils myExcelUtils;

    @Resource
    private IYcSysUserService ycSysUserService;

    @Resource
    private FlowJobBlsxService flowJobBlsxService;

    @Resource
    private BusinessConstant businessConstant;

    @Resource
    @Lazy
    private ZdyUploadFileService zdyUploadFileService;

    @Log(title = "用户培训记录-分页列表查询")
    @ApiOperation(value = "用户培训记录-分页列表查询")
    @GetMapping(value = "/queryPageList")
    public HttpResult<?> queryPageList(UserPxjlBo sysUserPxjl,
                                       @RequestParam(name = "year",defaultValue = "")String year,
                                       @RequestParam(value = "isSelectMe",defaultValue = "true")boolean isSelectMe,
                                       PageVo pageVo,
                                       OrderItemVo orderItemVo) {
        Page<SysUserPxjl> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        if (StringUtils.isNotBlank(sysUserPxjl.getFuserid())){
            isSelectMe = false;
        }
        IPage<SysUserPxjl> pageList = sysUserPxjlService.getPageList(page, sysUserPxjl, year, isSelectMe, orderItemVo);
        return HttpResult.ok(pageList);
    }

    @Log(title = "用户培训记录-所有列表")
    @ApiOperation(value = "用户培训记录-所有列表")
    @GetMapping(value = "/queryAllList")
    public HttpResult<?> queryAllList(UserPxjlBo sysUserPxjl,
                                      @RequestParam(value = "year",defaultValue = "")String year,
                                      @RequestParam(value = "isSelectMe",defaultValue = "true")boolean isSelectMe) {
        if (StringUtils.isNotBlank(sysUserPxjl.getFuserid())){
            isSelectMe = false;
        }
        List<SysUserPxjl> pageList = sysUserPxjlService.getList(sysUserPxjl, year, isSelectMe);
        return HttpResultVo.HttpResultList(pageList);
    }

    @Log(title = "用户培训记录-添加")
    @ApiOperation(value = "用户培训记录-添加")
    @PostMapping(value = "/addPxjl")
    public HttpResult<?> addPxjl(@RequestBody SysUserPxjl sysUserPxjl) {
        sysUserPxjl.setId(GetUuIdUtils.ReplaceUuId());
        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser == null){
            return HttpResult.error("登录已过期，请重新登录");
        }

        if (StringUtils.isBlank(sysUserPxjl.getFuserid())) {
            sysUserPxjl.setFuserid(currentUser.getId());
            sysUserPxjl.setFusermc(currentUser.getName());
        }else {
            YcSysUser user = ycSysUserService.getById(sysUserPxjl.getFuserid());
            if (user != null){
                sysUserPxjl.setFusermc(user.getRealname());
            }
        }

        if (sysUserPxjl.getFpxkssj() == null){
            throw new BusinessException("请输入开始时间！");
        }

        if (sysUserPxjl.getFpxjssj() == null){
            throw new BusinessException("请输入结束时间！");
        }

        if (sysUserPxjl.getFpxkssj().getTime() > sysUserPxjl.getFpxjssj().getTime()){
            throw new BusinessException("开始时间不能大于结束时间！");
        }

        if (StringUtils.isBlank(sysUserPxjl.getFjlnd())){
            sysUserPxjl.setFjlnd(DateConversionUtils.DateToYear(new Date()));
        }

        if (StringUtils.isBlank(sysUserPxjl.getFpxxs())){
            throw new BusinessException("请输入学时！");
        }

        // 验证是否输入中文
        if (StringPatternUtils.checkStringContainChinese(sysUserPxjl.getFpxxs())){
            throw new BusinessException("学时不能输入中文！");
        }

        // 验证输入的值，是否大于实际的值
        Float srxs = Float.valueOf(sysUserPxjl.getFpxxs());
        Integer jsxs = getPxxs(sysUserPxjl.getFpxkssj(), sysUserPxjl.getFpxjssj());
        if (srxs > jsxs){
            throw new BusinessException("保存失败，每天最多8小时，当前时间下学时最大值为[ "+jsxs+" ]！");
        }

        /*if (sysUserPxjl.getFpxkssj() != null && sysUserPxjl.getFpxjssj() != null && StringUtils.isBlank(sysUserPxjl.getFpxxs())){
            Integer pxxs = this.getPxxs(sysUserPxjl.getFpxkssj(), sysUserPxjl.getFpxjssj());
            sysUserPxjl.setFpxxs(pxxs.toString());
        }*/

        sysUserPxjl.setFpxly(SpcyConstant.Px_Pxly_Wb); // 外部培训
        sysUserPxjlService.save(sysUserPxjl);

        String operContent = "新增培训记录信息：";
        // 将map里面的属性和值转String
        Map<String, Object> beanMap = ObjectToMapUtils.objectToMap(sysUserPxjl);
        operContent += LogUtils.MapToStringMethod(beanMap);
        spcyLogService.addLogs(LogConstant.LOGS_SYS_USER_PXJL,operContent,sysUserPxjl.getId(), LogConstant.LOGS_SYS_USER_PXJL, SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult result = new HttpResult(true);
        result.setResult(sysUserPxjl);
        result.setMessage("添加成功");
        return result;
    }

    @Log(title = "用户培训记录-编辑")
    @ApiOperation(value = "用户培训记录-编辑")
    @ApiImplicitParam(name = "id",value = "用户培训记录id",required = true)
    @PutMapping(value = "/editPxjl")
    public HttpResult<?> editPxjl(@RequestBody SysUserPxjl buffer) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        if (StringUtils.isEmpty(buffer.getId())){
            return HttpResult.error("用户培训记录id不能为空");
        }
        String djjxxxId = buffer.getId();
        SysUserPxjl oldPxjl = sysUserPxjlService.getById(djjxxxId);

        // 内部培训不能编辑
        if (StringUtils.isNotBlank(oldPxjl.getFpxly()) && oldPxjl.getFpxly().equals(SpcyConstant.Px_Pxly_Nb)){
            return HttpResult.error("权限不足，内部培训不可修改。");
        }

        SysUserPxjl oldPxjlUpdate = sysUserPxjlService.getById(djjxxxId);
        if (oldPxjlUpdate == null){
            return HttpResult.error("当前用户培训记录基本信息数据不存在，请重试");
        }

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(oldPxjlUpdate, BeanUtils.describe(buffer));

        if (buffer.getFpxkssj() == null){
            throw new BusinessException("请输入开始时间！");
        }else {
            oldPxjlUpdate.setFpxkssj(buffer.getFpxkssj());
        }

        if (buffer.getFpxjssj() == null){
            throw new BusinessException("请输入结束时间！");
        }else {
            oldPxjlUpdate.setFpxjssj(buffer.getFpxjssj());
        }

        if (oldPxjlUpdate.getFpxkssj().getTime() > oldPxjlUpdate.getFpxjssj().getTime()){
            throw new BusinessException("开始时间不能大于结束时间！");
        }

        if (StringUtils.isBlank(oldPxjlUpdate.getFjlnd())){
            oldPxjlUpdate.setFjlnd(DateConversionUtils.DateToYear(new Date()));
        }

        if (StringUtils.isBlank(oldPxjlUpdate.getFpxxs())){
            throw new BusinessException("请输入学时！");
        }

        // 验证是否输入中文
        if (StringPatternUtils.checkStringContainChinese(oldPxjlUpdate.getFpxxs())){
            throw new BusinessException("学时不能输入中文！");
        }

        // 验证输入的值，是否大于实际的值
        Float srxs = Float.valueOf(oldPxjlUpdate.getFpxxs());
        Integer jsxs = getPxxs(oldPxjlUpdate.getFpxkssj(), oldPxjlUpdate.getFpxjssj());
        if (srxs > jsxs){
            throw new BusinessException("保存失败，每天最多8小时，当前时间下学时最大值为[ "+jsxs+" ]！");
        }

        sysUserPxjlService.updateById(oldPxjlUpdate);

        String operContent = "基本信息修改：";
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(oldPxjl);
        operContent += LogUtils.BeanModifyMsg(oldPxjlUpdate,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_SYS_USER_PXJL,operContent,djjxxxId,LogConstant.LOGS_SYS_USER_PXJL,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("修改成功");
    }

    @Log(title = "用户培训记录-批量删除")
    @ApiOperation(value = "用户培训记录-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam(value = "ids",defaultValue = "") String ids) {
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空!");
        }
        List<String> idsList = StringPatternUtils.getListByIds(ids);
        List<SysUserPxjl> sysUserPxjls = sysUserPxjlService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sysUserPxjls)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        String msg = "";
        for (SysUserPxjl pxjl : sysUserPxjls){
            // 内部培训不能删除
            if (StringUtils.isNotBlank(pxjl.getFpxly()) && pxjl.getFpxly().equals(SpcyConstant.Px_Pxly_Nb)){
                msg += "【"+pxjl.getFpxmc()+"】属于【"+SpcyConstant.Px_Pxly_Nb+"】无法删除。\n";
                continue;
            }

            String id = pxjl.getId();
            sysUserPxjlService.removeById(id);

            // 删除文件
            zdyUploadFileService.deleteFileByBatch(id);

            operContent = "删除信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(pxjl);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_SYS_USER_PXJL,operContent,id,LogConstant.LOGS_SYS_USER_PXJL,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }
        if (StringUtils.isBlank(msg)){
            msg = "删除成功";
        }
        return HttpResult.ok(msg);
    }

    @Log(title = "用户培训记录-通过id查询")
    @ApiOperation(value = "用户培训记录-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        SysUserPxjl sysUserPxjl = sysUserPxjlService.getById(id);
        return HttpResult.ok(sysUserPxjl);
    }

    @Log(title = "获取培训学时")
    @ApiOperation(value = "获取培训学时")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "fpxkssj",value = "培训开始时间"),
            @ApiImplicitParam(name = "fpxjssj",value = "培训结束时间")
    })
    @GetMapping(value = "getPxxs")
    public HttpResult getPxxs(@RequestParam(value = "fpxkssj",defaultValue = "")String fpxkssj,
                              @RequestParam(value = "fpxjssj",defaultValue = "")String fpxjssj){

        if (StringUtils.isBlank(fpxkssj)){
            return HttpResult.error("请填写培训开始时间！");
        }
        if (StringUtils.isBlank(fpxjssj)){
            return HttpResult.error("请填写培训结束时间！");
        }
        Date kssj = DateUtil.parse(fpxkssj);
        Date jssj = DateUtil.parse(fpxjssj);
        Integer pxxs = this.getPxxs(kssj, jssj);


        Map resultMap = new HashMap();
        resultMap.put("fpxxs",pxxs);
        return HttpResult.ok(resultMap);
    }

    private Integer getPxxs(Date kssj,Date jssj){
        String jssygzr = flowJobBlsxService.jspxsx(kssj, jssj);
        BigDecimal gzr = new BigDecimal(jssygzr).setScale(0, BigDecimal.ROUND_DOWN);
        BigDecimal dayXs = new BigDecimal("8");
        BigDecimal xsgzr = gzr.multiply(dayXs);
        BigDecimal xs = xsgzr.setScale(0, BigDecimal.ROUND_DOWN);

        return Integer.valueOf(xs.toString());
    }

    @Log(title = "查询培训记录-相关文件")
    @ApiOperation(value = "查询培训记录-相关文件")
    @ApiImplicitParam(name = "id",value = "培训记录id")
    @GetMapping(value = "queryPxjlFileList")
    public HttpResult<?> queryPxjlFileList(@RequestParam(value = "id",defaultValue = "") String id){
        if (StringUtils.isEmpty(id)){
            return HttpResult.error("培训记录参数不能为空");
        }

        List<SpcySqsxWjjl> wjjlList = zdyUploadFileService.queryWjjlByPid(id);
        return HttpResult.ok(wjjlList);
    }

    @Log(title = "上传文件-培训记录文件")
    @ApiOperation(value = "上传文件-培训记录文件")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "file",value = "文件不能为空",required = true),
            @ApiImplicitParam(name = "id",value = "培训记录id",required = true)
    })
    @PostMapping(value = "/uploadPxjlFile")
    public HttpResult<?> uploadPxjlFile(@RequestPart("file") MultipartFile[] uploadFile,
                                        @RequestParam(value = "id",defaultValue = "") String id){

        zdyUploadFileService.uploadFile(uploadFile, id, LogConstant.LOGS_SYS_USER_PXJL, SpcyConstant.Px_File_Base_Url);
        return HttpResult.ok("上传成功");
    }

    @Log(title = "下载文件-培训记录文件")
    @ApiOperation(value = "下载文件-培训记录文件")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "文件id",required = true)
    })
    @GetMapping(value = "/getPxjlFile")
    public void getPxjlFile(@RequestParam(value = "id",defaultValue = "") String fileId, HttpServletResponse response) {
        zdyUploadFileService.downloadFile(fileId, response);
    }

    @Log(title = "删除文件-培训记录文件")
    @ApiOperation(value = "删除文件-培训记录文件")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "文件id",dataType = "String",required = true),
    })
    @DeleteMapping(value = "/deletePxjlFileById")
    public HttpResult<?> deletePxjlFileById(@RequestParam(value = "id",defaultValue = "")String fileId){
        zdyUploadFileService.deleteFile(fileId, LogConstant.LOGS_SYS_USER_PXJL);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "导入培训记录基本信息数据-表格excel")
    @ApiOperation(value = "导入培训记录基本信息数据-表格excel")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "file",value = "excel模板文件",required = true)
    })
    @PostMapping(value = "impPxjlData")
    public HttpResult<?> impPxjlData(@RequestParam("file") MultipartFile file,
                                     @RequestParam(value = "fuserid",defaultValue = "")String userid){
        if (file.isEmpty()){
            return HttpResult.error("文件为空!");
        }

        CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
        if (currentUser == null){
            log.error("登录过期，导入失败");
            return HttpResult.error("登录已失效，请重新登录");
        }

        if (StringUtils.isBlank(userid)){
            userid = currentUser.getId();
        }

        //获取文件名
        String fileName = file.getOriginalFilename();

        //判断文件类型，这里我们只要xls文件
        if (fileName != null && !fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) {
            return HttpResult.error(1, "请选择“xls”或“xlsx”文件");
        }

        File fileUpload = localFileUploadUtils.uploadDempFile(file,fileName);

        // 获取导入的数据
        List<Map<String, Object>> mapsList = null;
        try {
            mapsList = myExcelUtils.paresExclToMapList(BusinessConstant.IMPORT_SYS_PXJL_SECODE_XML, fileUpload);
        } catch (Exception e) {
            log.error("导入培训记录基本信息数据出错-{}",e.getMessage());
        }

        List<SysUserPxjl> pxjlList = new ArrayList<>();
        for (int order=0; order<mapsList.size(); order++){
            ImportUserPxjlBo pxjlBo = new ImportUserPxjlBo();
            BeanUtil.copyProperties(mapsList.get(order),pxjlBo);

            if (StringUtils.isBlank(pxjlBo.getRealname())){
                throw new BusinessException("第"+order+"条导入失败！姓名为空！");
            }

            if (StringUtils.isBlank(pxjlBo.getFsfzh())){
                throw new BusinessException("第"+order+"条导入失败！身份证号为空！");
            }

            String usermc = "";
            List<YcSysUser> userList = ycSysUserService.list(new LambdaQueryWrapper<YcSysUser>()
                    .eq(YcSysUser::getFsfzh, pxjlBo.getFsfzh()));
            if (CollectionUtil.isEmpty(userList)){
                throw new BusinessException("身份证号为【"+pxjlBo.getFsfzh()+"】人员不存在系统中！");
            }else {
                userid = userList.get(0).getId();
                usermc = userList.get(0).getRealname();
            }

            SysUserPxjl pxjl = new SysUserPxjl();
            pxjl.setId(GetUuIdUtils.ReplaceUuId());
            pxjl.setFjlnd(pxjlBo.getFjlnd());
            pxjl.setFuserid(userid);
            pxjl.setFusermc(usermc);
            pxjl.setFpxmc(pxjlBo.getFpxmc());
            pxjl.setFpxnr(pxjlBo.getFpxnr());
            pxjl.setFpxxs(pxjlBo.getFpxxs());
            pxjl.setFpxlx(pxjlBo.getFpxlx());
            if (StringUtils.isBlank(pxjlBo.getFjlnd())){
                pxjl.setFjlnd(DateConversionUtils.DateToYear(new Date()));
            }else {
                pxjl.setFjlnd(pxjlBo.getFjlnd());
            }

            if (StringUtils.isNotBlank(pxjlBo.getFpxkssj())) {
                pxjl.setFpxkssj(DateUtil.parse(pxjlBo.getFpxkssj()));
            }

            if (StringUtils.isNotBlank(pxjlBo.getFpxjssj())) {
                pxjl.setFpxjssj(DateUtil.parse(pxjlBo.getFpxjssj()));
            }

            pxjl.setCreateTime(new Date());
            pxjlList.add(pxjl);

            String operContent = "新增导入培训记录信息：";
            Map<String, Object> bhgzMap = ObjectToMapUtils.objectToMap(pxjl);
            operContent += LogUtils.MapToStringMethod(bhgzMap);
            spcyLogService.addLogs(LogConstant.LOGS_SYS_USER_PXJL,operContent,pxjl.getId(),LogConstant.LOGS_SYS_USER_PXJL,SpcyConstant.LOGS_SYS_TYPE_XZ);
        }

        sysUserPxjlService.saveBatchPxjl(pxjlList);

        fileUpload.delete();
        return HttpResult.ok("导入成功");
    }

    @Log(title = "下载用户培训记录-导入模板")
    @ApiOperation(value = "下载用户培训记录-导入模板")
    @GetMapping("/downUserPxjlTemplate")
    public void downUserPxjlTemplate(HttpServletResponse response){
        try {
            response.setContentType("application/ms-excel;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode("userPxjlImpTemplate.xls", "UTF-8"))));
            OutputStream out = response.getOutputStream();
            myExcelUtils.buildImpModel(BusinessConstant.IMPORT_SYS_PXJL_SECODE_XML, out);
        } catch (Exception e) {
            log.error("下载用户培训记录模板错误-{}",e.getMessage());
        }
    }

    @Log(title = "导出用户培训记录数据-表格excel")
    @ApiOperation(value = "导出用户培训记录数据-表格excel")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "ids",value = "培训记录id,字符逗号分割",dataType = "String"),
            @ApiImplicitParam(name = "fuserid",value = "用户id",required = true),
            @ApiImplicitParam(name = "year",value = "年份",dataType = "String"),
            @ApiImplicitParam(name = "isExportMe",value = "默认导出所有，导入个人值为[是]",dataType = "String")
    })
    @GetMapping("/exportUserPxjlData")
    public void exportUserPxjlData(@RequestParam(value = "ids",defaultValue = "")String ids,
                                   UserPxjlBo pxjl,
                                   @RequestParam(value = "year",defaultValue = "")String year,
                                   @RequestParam(value = "isExportMe",defaultValue = "true")boolean isExportMe,
                                   HttpServletResponse response){
        List<List<String>> resultList = new ArrayList<>();

        // 表头
        String[] titles = new String[]{"序号","认定内容","姓名","身份证号","申请学时","认定类型","开始时间(YYYY-MM-DD HH:mm)","记录年度(YYYY)","结束时间/获得时间(YYYY-MM-DD HH:mm)","认定内容说明"};
        List<String> titleList = CollectionUtil.newArrayList(titles);
        resultList.add(titleList);

        List<SysUserPxjl> pxjlList = new ArrayList<>();

        // 多选导出
        if (StringUtils.isNotEmpty(ids)) {
            List<String> IdsList = StringPatternUtils.getListByIds(ids);
            pxjlList = sysUserPxjlService.listByIds(IdsList);
        }else {
            if (StringUtils.isNotBlank(pxjl.getFuserid())){
                isExportMe = false;
            }
            pxjlList = sysUserPxjlService.getList(pxjl, year, isExportMe);
        }

        for (int i = 0; i<pxjlList.size(); i++){
            // 数据
            List<String> dataList = new ArrayList<>();

            YcSysUser user = ycSysUserService.getById(pxjlList.get(i).getFuserid());

            dataList.add(String.valueOf(i+1));
            dataList.add(pxjlList.get(i).getFpxmc());
            dataList.add(user.getRealname());

            dataList.add(user.getFsfzh());
            dataList.add(pxjlList.get(i).getFpxxs());
            dataList.add(pxjlList.get(i).getFpxlx());

            if (pxjlList.get(i).getFpxkssj() != null) {
                dataList.add(DateConversionUtils.DateToYMDMM(pxjlList.get(i).getFpxkssj()));
            }else {
                dataList.add("");
            }

            dataList.add(pxjlList.get(i).getFjlnd());

            if (pxjlList.get(i).getFpxjssj() != null) {
                dataList.add(DateConversionUtils.DateToYMDMM(pxjlList.get(i).getFpxjssj()));
            }else {
                dataList.add("");
            }

            dataList.add(pxjlList.get(i).getFpxnr());

            resultList.add(dataList);
        }

        // 文件名称
        String title = "学员培训信息基础信息";

        String rootUrl = localFileUploadUtils.getTempFileRootUrl();

        File outFile = ExcelUtils.getLocalDempXlsExcel(resultList, title, rootUrl);

        localFileUploadUtils.ejzLocalFileByZdyFile(outFile,response);
    }

}
